package net.adriana.bean;

import java.util.Arrays;

import net.adriana.esaytool.Logger;
import net.adriana.esaytool.util.MetaDataUtil;

public class Schema {
	/**
	 * 数据库名称
	 */
	private String schemaName;
	/**
	 * 表
	 */
	private Table[] tables;
	
	public Schema() {
		super();
	}
	
	
	public Table getTableByName(String name){
		for (Table table : tables) {
			if(table.getTableName() == name)return table;
		}
		return null;
	}
	public String[] getTablesName(){
		String[] tablesName = new String[tables.length];
		for (int i = 0; i < tables.length; i++) {
			tablesName[i] = tables[i].getTableName();
		}
		return tablesName;
	}
	
	public String[] getStdTablesName(){
		String[] tablesName = new String[tables.length];
		for (int i = 0; i < tables.length; i++) {
			tablesName[i] = tables[i].getStdTableName();
		}
		return tablesName;
	}
	
	public String getSchemaName() {
		return schemaName;
	}
	public void setSchemaName(String schemaName) {
		MetaDataUtil.DATABASE = schemaName;
		Logger.log(Logger.WARING, "设置数据库名称：" + schemaName);
		this.schemaName = schemaName;
	}
	public Table[] getTables() {
		return tables;
	}
	public void setTables(Table[] tables) {
		for (Table table : tables) {
			table.setSchema(this);
		}
		this.tables = tables;
	}
	@Override
	public String toString() {
		return "Schem [schemaName=" + schemaName + ", tables=" + 
				Arrays.toString(getTablesName()) + "]";
	}
	
}
